<template>
  <div class="hello">
    <h1>{{msg}}</h1>
    <input v-model="newitem" @keyup.enter="addNew" placeholder="回车添加" style="width:40%"></input>
    <ol v-for="(item,index) in items">
      <li  :class="{finished:item.finished}" @click="finishing(item)" >{{index + 1}}.{{item.title}}
      </li>
    </ol>
    </div>
</template>

<script>
import store from '../stroage'
export default {
  name: 'hello',
  data () {
    return {
      msg: '这是一个简单的todoList 列表',
      items: store.get(),
      newitem:''
    }
  },
  methods:{
    addNew () {
        if(this.newitem.trim().length !== 0){
          var obj = {title:this.newitem,finished:false}
          this.items.push(obj)
          this.newitem = ''
        }
    },
    delete(index){
        this.item.remove(index)
    },
    finishing (item) {
        item.finished = ! item.finished
    }
  },
  watch: {
    items:{
      handler: function (items) {
        store.save(items)
       },
       deep: true
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.finished {
  color:red;
  text-decoration:line-through;
}

li:hover {
  font-weight:bold;
  font-size:30px;
}

h1, h2 {
  font-weight: normal;
}

ul {
  list-style-type: none;
  padding: 0;
}

li {
  display: inline-block;
  margin: 0 10px;
}

a {
  color: #42b983;
}
</style>
